// 小说基础类型
export interface Novel {
  id: number
  title: string
  author: string
  description: string | null
  coverImage: string | null
  status: number
  masterCategoryId: number | null
  masterCategory?: NovelCategory
  wordCount: number
  readCount: number
  favoriteCount: number
  ratingScore: number
  ratingCount: number
  tags: string[] | null
  platform: string | null
  originalUrl: string | null
  createdAt: string
  updatedAt: string
  // 用户相关字段（仅当用户登录时返回）
  isFavorited?: boolean
  favoriteBookshelfId?: number | null
}

// 小说分类
export interface NovelCategory {
  id: number
  name: string
  code: string
  description?: string
  sort: number
  status: number
  createdAt: string
  updatedAt: string
}

// 小说章节
export interface NovelChapter {
  id: number
  novelId: number
  title: string
  content: string
  wordCount: number
  chapterNumber: number
  price?: number
  isVip: boolean
  status: number
  createdAt: string
  updatedAt: string
}

// 用户收藏
export interface UserFavorite {
  id: number
  userId: number
  novelId: number
  novel?: Novel
  createdAt: string
}

// 阅读历史
export interface UserReadingHistory {
  id: number
  userId: number
  novelId: number
  novel?: Novel
  chapterId?: number
  chapter?: NovelChapter
  readProgress: string
  readPosition?: number
  lastReadAt: string
  createdAt: string
  updatedAt: string
}

// 评论
export interface Comment {
  id: number
  userId: number
  user?: {
    id: number
    username: string
    nickname?: string
    avatar?: string
  }
  novelId: number
  novel?: Novel
  chapterId?: number
  chapter?: NovelChapter
  parentId?: number | null
  parent?: Comment
  replies?: Comment[]
  content: string
  likeCount: number
  status: number
  createdAt: string
  updatedAt: string
}

// 分页响应
export interface PaginatedResponse<T> {
  items: T[]
  meta: {
    page: number
    limit: number
    total: number
    totalPages: number
    hasNext: boolean
    hasPrev: boolean
  }
}

// API 请求参数
export interface NovelListParams {
  page?: number
  limit?: number
  keyword?: string
  categoryId?: number
  status?: number
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
}

export interface ChapterListParams {
  page?: number
  limit?: number
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
}

export interface CommentListParams {
  novelId: number
  chapterId?: number
  page?: number
  limit?: number
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
  isHot?: boolean
  onlyAuthor?: boolean
}

export interface FavoriteParams {
  page?: number
  limit?: number
  categoryCode?: string
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
}

export interface ReadingHistoryParams {
  page?: number
  limit?: number
  categoryCode?: string
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
}

// 请求体
export interface AddFavoriteRequest {
  novelId: number
  bookshelfId?: number
}

export interface AddReadingHistoryRequest {
  novelId: number
  chapterId?: number
  readProgress?: string
}

export interface CreateCommentRequest {
  novelId: number
  chapterId?: number
  content: string
  parentId?: number | null
}

export interface UpdateCommentRequest {
  content: string
}

// 用户统计
export interface UserStats {
  favoriteCount: number
  readingHistoryCount: number
  commentCount: number
  totalReadTime: number
  continuousReadingDays: number
}

// 阅读偏好
export interface ReadingPreferences {
  favoriteCategory?: number
  favoriteCategoryCount?: number
  peakReadingTime?: string
  totalBooksRead?: number
  averageBooksPerWeek?: number
}

// 推荐小说参数
export interface RecommendedNovelsParams {
  limit?: number
}

// ==================== 书架管理 ====================

// 书架
export interface Bookshelf {
  id: number
  userId: number
  name: string
  description: string | null
  sortOrder: number
  isDefault: boolean
  status: number
  bookCount?: number // 书籍数量统计
  createdAt: string
  updatedAt: string
}

// 收藏记录（扩展版）
export interface UserFavoriteExtended extends UserFavorite {
  bookshelf?: Bookshelf
  bookshelfId?: number
}

// 创建书架请求
export interface CreateBookshelfRequest {
  name: string
  description?: string
  sortOrder?: number
}

// 更新书架请求
export interface UpdateBookshelfRequest {
  name?: string
  description?: string
  sortOrder?: number
}

// 获取书架列表参数
export interface BookshelfParams {
  page?: number
  limit?: number
  sortBy?: 'name' | 'sortOrder' | 'createdAt'
  sortOrder?: 'asc' | 'desc'
}

// 移动收藏到书架请求
export interface MoveFavoritesRequest {
  bookshelfId: number
  novelIds: number[]
}

// 扩展的收藏参数
export interface FavoriteParamsExtended extends FavoriteParams {
  bookshelfId?: number
}